package com.gjs.demo002;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;

import com.gjs.demo002.adapter.MyRecyclerAdapter;
import com.gjs.demo002.bean.RecyclerBean;

import java.util.ArrayList;
import java.util.List;

public class MyRecyclerActivity extends AppCompatActivity {

    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_recycler);
        initView(); // 初始化控件
    }

    private void initView() {
        recyclerView = findViewById(R.id.activity_recyclerview);
        /**
         * 1.准备数据
         * 2.定义adapter
         * 3.setAdapter
         */
        List<RecyclerBean> list = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            RecyclerBean recyclerBean = new RecyclerBean();
            recyclerBean.setTitle("第"+(i+1)+"个");
            list.add(recyclerBean);
        }

        MyRecyclerAdapter adapter = new MyRecyclerAdapter(list,MyRecyclerActivity.this);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

    }
}